import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import { Input, Select } from "antd";
import { CpasIcon } from "~/public/cpas-ui";
const RowFilterFun = ({ columnsData, onDelete, filterObj, defaultFilterObj, filterObjArr, onValueChange, keys, type,
//   onSave,
 }) => {
    const [leftKuohao, setLeftKuohao] = useState(defaultFilterObj?.leftKuohao ?? "(");
    const [rightKuohao, setRightKuohao] = useState(defaultFilterObj?.rightKuohao ?? ")");
    const [text1, setText1] = useState(defaultFilterObj?.text1 ?? "且");
    const [fieldList, setFieldList] = useState([]);
    const [filterField, setFilterField] = useState(defaultFilterObj?.filterField ?? "");
    const [condionList, setCondionList] = useState([]);
    const [condions, setCondions] = useState(defaultFilterObj?.condions ?? "");
    const [filterVal, setFilterVal] = useState(defaultFilterObj?.filterVal ?? "");
    const [fieldType, getFieldType] = useState(defaultFilterObj?.fieldType ?? "");
    filterObj = {
        leftKuohao: leftKuohao,
        rightKuohao: rightKuohao,
        text1: text1,
        filterField: filterField,
        condions: condions,
        filterVal: filterVal,
        type: fieldType,
    };
    filterObjArr = filterObjArr || [];
    // 底稿结构化 -- 筛选 -- 左括号
    const getText1 = (e) => {
        if (e.target.value === "") {
            setLeftKuohao("(");
        }
        else {
            setLeftKuohao("");
        }
        // onValueChange(e.target.value);
        filterObj.leftKuohao = e.target.value;
        onValueChange(filterObj, keys, type);
    };
    //左括号改变
    function onLeftKuohaoChange(event) {
        filterObj.leftKuohao = event.target.value;
        setLeftKuohao(filterObj.leftKuohao);
        onValueChange(filterObj, keys, type);
    }
    //左括号改变
    function onRightuohaoChange(event) {
        filterObj.rightKuohao = event.target.value;
        setRightKuohao(filterObj.rightKuohao);
        onValueChange(filterObj, keys, type);
    }
    // 底稿结构化 -- 筛选 条件 且 或
    const ckText = () => {
        let newText1 = text1 === "且" ? "或" : "且";
        setText1(newText1);
        filterObj.text1 = newText1;
        //  text1 === "且" ? setText1("或") : setText1("且");
        // text1 === "且" ? (filterObj.text1 = "且") : (filterObj.text1 = "或");
        onValueChange(filterObj, keys, type);
    };
    // 底稿结构化 -- 筛选 - 列字段名称列表 为dev表的表头  this.props.columnsData
    const trasferField = () => {
        const fields = columnsData.map((item) => {
            return { value: item.caption, label: item.caption, type: item.fieldType };
        });
        setFieldList(fields);
    };
    // 底稿结构化 --筛选 列字段下拉事件
    const changeField = (val, item) => {
        setFilterField(val);
        filterObj.filterField = val;
        filterObj.type = item.type;
        onValueChange(filterObj, keys, item.type);
        getFieldType(item.type); // 为 fieldType 赋值
    };
    // 底稿结构化 -- 筛选 条件下拉框
    const conditionOptions = () => {
        const condionList = [
            // {
            //   value: "前几项",
            //   label: "前几项",
            // },
            // {
            //   value: "后几项",
            //   label: "后几项",
            // },
            {
                value: "=",
                label: "等于",
            },
            {
                value: "!=",
                label: "不等于",
            },
            {
                value: ">",
                label: "大于",
            },
            {
                value: ">=",
                label: "大于或等于",
            },
            {
                value: "<",
                label: "小于",
            },
            {
                value: "<=",
                label: "小于或等于",
            },
            {
                value: "like",
                label: "包含",
            },
            {
                value: "not like",
                label: "不包含",
            },
        ];
        setCondionList(condionList);
    };
    // 底稿结构化 -- 筛选 条件下拉点击
    const changeCondion = (val) => {
        setCondions(val);
        filterObj.condions = val;
        onValueChange(filterObj, keys, type);
    };
    // 底搞结构化 -- 筛选 -- 输入值
    const getInpVal = (e) => {
        setFilterVal(e.target.value);
        filterObj.filterVal = e.target.value;
        onValueChange(filterObj, keys, type);
    };
    useEffect(() => {
        conditionOptions();
        trasferField();
    }, []);
    return (_jsx(_Fragment, { children: _jsx("div", { className: "addRows", children: _jsxs("div", { className: "flex-start", children: [_jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { style: {
                                    border: "0px solid #000",
                                    width: "30px",
                                    height: "22px",
                                }, children: " " }), _jsx("div", { className: "fang cur", onClick: ckText, children: text1 })] }), _jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { children: "\u62EC\u5F27" }), _jsx("div", { className: "w30", style: { width: 40 }, children: _jsx(Input, { type: "text", value: leftKuohao, defaultValue: leftKuohao, onChange: onLeftKuohaoChange }) })] }), _jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { children: "\u5217\u5B57\u6BB5\u540D\u79F0" }), _jsx("div", { className: "", children: _jsx(Select, { defaultValue: filterField, value: filterField, style: { width: 150 }, options: fieldList, onChange: changeField }) })] }), _jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { children: "\u6761\u4EF6" }), _jsx("div", { className: "", children: _jsx(Select, { defaultValue: condions, value: condions, style: { width: 100 }, options: condionList, onChange: changeCondion }) })] }), _jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { children: "\u503C" }), _jsx("div", { className: "", children: _jsx(Input, { type: "text", value: filterVal, onChange: getInpVal }) })] }), _jsxs("div", { className: "flex-col mr-8", children: [_jsx("div", { children: "\u62EC\u5F27" }), _jsx("div", { className: "w30", style: { width: 40 }, children: _jsx(Input, { type: "text", value: rightKuohao, defaultValue: rightKuohao, onChange: onRightuohaoChange }) })] }), _jsxs("div", { className: "flex-col cur", children: [_jsx("div", { style: {
                                    border: "0px solid #000",
                                    width: "20px",
                                    height: "28px",
                                } }), _jsx(CpasIcon, { className: "icon-size16", type: "icon-delete", onClick: () => {
                                    onDelete(keys);
                                } })] })] }) }) }));
};
export default RowFilterFun;
